//
//  HBEmotionButton.swift
//  sinaWeibo
//
//  Created by Beans on 16/7/2.
//  Copyright © 2016年 iceWorks. All rights reserved.
//

import UIKit

class HBEmotionButton: UIButton {

    var emotion: HBEmotion? {
        didSet {

            // 2. 赋值
            // 如何去区分图片表情和emoji? 通过对象里emoji与png为空的情况

            // 2.1 图片表情
            if let png = emotion?.png, path = emotion?.path {
                let imageName = "\(path)/\(png)"    // "\(emotion.path)/\(emotion.png)"未解包
                self.setImage(UIImage(named: imageName), forState: .Normal)
            } else {
                // 一定要注意cell重用
                self.setImage(nil, forState: .Normal)
            }

            // 2.2 emoji
            if let emoji = emotion?.emoji {
                self.setTitle(emoji, forState: .Normal)
                self.titleLabel?.font = UIFont.systemFontOfSize(32.0)
            } else {
                self.setTitle(nil, forState: .Normal)
            }

        }
    }

}
